package com.springapi.controller;

import com.springapi.entity.Orderev;
import com.springapi.service.OrderevService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 系统设置
实付金额=合计金额或vip合计金额 -折扣金额-生日金额-抹零金额(Orderev)表控制层
 *
 * @author makejava
 * @since 2025-01-07 08:37:55
 */
@RestController
@RequestMapping("/api/orderev")
public class OrderevController {
    /**
     * 服务对象
     */
    @Resource
    private OrderevService orderevService;



    @GetMapping("/getcountorderev")
    public Double getcountorderev(@RequestParam int appid, @RequestParam int shopid, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date  createdate1, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date createdate2) {
        Double res=0.00;
        try {

            res= orderevService.getcountorderev(appid,shopid,createdate1,createdate2);
        } catch (Exception e) {
            e.printStackTrace();

        }
        return res;
    }


    @GetMapping("/getsumpayamount")
    public Double getsumpayamount(@RequestParam int appid, @RequestParam int shopid, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date  createdate1, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date createdate2) {
        Double res=0.00;
        try {
            res= orderevService.getsumpayamount(appid,shopid,createdate1,createdate2);
        } catch (Exception e) {
           e.printStackTrace();

        }
        return res;
    }


    /**
     * 分页查询
     *
     * @param orderev 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Orderev>> queryByPage(Orderev orderev, PageRequest pageRequest) {
        return ResponseEntity.ok(this.orderevService.queryByPage(orderev, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Orderev> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.orderevService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param orderev 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Orderev> add(@RequestBody Orderev orderev) {
        return ResponseEntity.ok(this.orderevService.insert(orderev));
    }

    /**
     * 编辑数据
     *
     * @param orderev 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Orderev> edit(Orderev orderev) {
        return ResponseEntity.ok(this.orderevService.update(orderev));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.orderevService.deleteById(id));
    }

}

